<?php 
/**
 * Using:
 * 1) USING: create configuration file to DOM_CONF_DIR_PATH/banklink.conf.php (See sample-conf.php)
 * 2) Call BankLog::getTable()->update()
 *
 * @package BankLink
 * @author Oliver Leisalu
 */


// Start Dom framework and connect to database


// direct user to bank
if( $_POST['bank'] ) {
	
	// UID, price, description, bank[swed|seb|sampo|nordea|estcard|dummy|ipx]
	$payment = new BankPayment( 100, $_POST['price'], 'Test buy', $_POST['bank'] );
	// You can access this data same way when user comes back from bank.
	$payment->userData = array('someKey' => 'SomeInfo');
	// send user to bank (Basicly outputs some html and calls die() )
	BankPaymentHandler::sendToBank( $payment );


// handle replay (User comes back from bank)
} else if( $_POST ) {
	$replay = BankPaymentHandler::handleReplay( );
	
	if( $replay->status === 1 ) {
		echo '<h3>Successful payment</h3>';
	
	} elseif( $replay->status == 2 ) {
	 	echo '<h3>Payment already processed!</h3>';
	
	} elseif( $replay->status == 3 ) {
		echo '<h3>User cancelled payment!</h3>';
	
	} else {
		echo '<h3>Error: '.$replay->statusStr.'</h3>';
	}	

	echo '<b>Payment info</b><br>';
	echo '<b>Uid</b>: '.$replay->uid.'<br>';
	echo '<b>PaymentId</b>: '.$replay->logId.'<br>';
	echo '<b>Price</b>:'.$replay->price.' '.$replay->currency.'<br>';
	echo '<b>Bank</b>:'.$replay->bank.'<br>';
	echo '<b>Payment description</b>: '.$replay->description.'<br>';
	echo '<b>Added user data:</b><br>';
	echo '<pre>';
	print_r( $replay->userData );
	echo '</pre>';
	
}
?>


<form name="form" action="" method="post">
	<input type="text" value="0.01" name="price">
	<br>
	<?php foreach( BankPaymentHandler::getUsableBanks() as $bank ):?>
	<img src="<?php echo $bank['icon'] ?>" alt="<?php echo $bank['key'] ?>"/>
	<input type="submit" name="bank" value="<?php echo $bank['key'] ?>"><br>
	<?php endforeach;?>
</form>